package spring.forkjoin;

import java.util.concurrent.ThreadLocalRandom;



public class TestMain {

	static final int MAX_CAP = 0x7fff;  
	private static final int  RSLOCK     = 1;
	private static final int  STARTED    = 1 << 2;
	static final int SMASK        = 0xffff;   
	static final int FIFO_QUEUE   = 1 << 16;
	static final int SQMASK       = 0x007e;      
	private static final int  AC_SHIFT   = 48;
	private static final long AC_MASK    = 0xffffL << AC_SHIFT;
	private static final int  TC_SHIFT   = 32;
	private static final long TC_MASK    = 0xffffL << TC_SHIFT;
	private static final long ADD_WORKER = 0x0001L << (TC_SHIFT + 15);
	private static final long AC_UNIT    = 0x0001L << AC_SHIFT;
	private static final long TC_UNIT    = 0x0001L << TC_SHIFT;
	private static final int SHARED_QUEUE = 1 << 31;
	
	public static void main(String[] args) {
		System.out.println(MAX_CAP);
		System.out.println(Math.min(MAX_CAP, Runtime.getRuntime().availableProcessors()));
		
		int rs = 0;
		System.out.println(rs |= RSLOCK);
		System.out.println("STARTED:"+STARTED);
		System.out.println("rs:"+rs);
		System.out.println(rs & STARTED);
		//默认情况
		System.out.println((Runtime.getRuntime().availableProcessors() & SMASK) | FIFO_QUEUE);
		
		System.out.println((16 & SMASK));
		
		int p = 16;
		int n = (p > 1) ? p - 1 : 1;
        n |= n >>> 1; n |= n >>> 2;  n |= n >>> 4;
        n |= n >>> 8; n |= n >>> 16; n = (n + 1) << 1;
        System.out.println("n:"+n);
		
        System.out.println("SQMASK:"+SQMASK);
        rs = 1;
        System.out.println((rs & ~RSLOCK) | STARTED);
        rs =4;
        System.out.println(rs & ~RSLOCK);
        
       
        System.out.println(0L < 0L);
        long np = -4;
        long test = ((np << AC_SHIFT) & AC_MASK) | ((np << TC_SHIFT) & TC_MASK);
        System.out.println(test);
        
        int testInt = (int)test;
        System.out.println(test & ADD_WORKER);
        long nc = ((AC_MASK & (test + AC_UNIT)) |
                (TC_MASK & (test + TC_UNIT)));
        System.out.println(nc);
        
        System.out.println(0 & ~RSLOCK);
        
        System.out.println((4 & SMASK) | 0);
        
        System.out.println(0 | SHARED_QUEUE);
        
        System.out.println(1 << 13);
	}

}
